package com.xh.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;

/**
 * @author 史建飞
 * @version 1.0
 */
public class EnumConstraintValidator implements ConstraintValidator<EnumValidate,Integer> {
    private HashSet<Integer> set = new HashSet<>();

    @Override
    public void initialize(EnumValidate constraintAnnotation) {
        int[] values = constraintAnnotation.values();

        for (int value : values){
            set.add(value);
        }
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
